package response

import (
	"net/http"

	"gitee.com/go-kade/go12/vblog/exception"
	"github.com/gin-gonic/gin"
)

//g.JSON(http.StatusBadRequest, err.Error())

func Success(g *gin.Context, data any) {
	g.JSON(http.StatusOK, data)
}

func Failed(g *gin.Context, err error) {
	var e *exception.ApiException
	if v, ok := err.(*exception.ApiException); ok {
		e = v
	} else {
		e = exception.NewError(http.StatusInternalServerError, err.Error())
		e.HttpCode = http.StatusInternalServerError
	}
	g.JSON(e.BizCode, e)
}
